﻿@page "/tests/datagrid/auto-generate-columns"
@using System.ComponentModel.DataAnnotations
<Row>
    <Column>
        <Card Margin="Margin.Is4.OnY">
            <CardHeader>
                <CardTitle>Datagrid: Auto Generate Columns</CardTitle>
            </CardHeader>
            <CardBody>
                <DataGrid TItem="Example"
                          Data="data"
                          Responsive
                          ShowPager
                          ShowPageSizes Editable>
                    <DataGridCommandColumn TItem="Example" />
                </DataGrid>
            </CardBody>
        </Card>
    </Column>
</Row>

@code {

    public class Example
    {
        [Order( DisplayOrder = 1, EditOrder = 2 )]
        [Display(Name = "Name")]
        public string FirstName { get; set; }

        [Order( DisplayOrder = 2, EditOrder = 3 )]
        public string LastName { get; set; }

        [Order( DisplayOrder = 3, EditOrder = 4 )]
        [Numeric(EnableStep = true, ShowStepButtons = true, Step = 1)]
        public int Age { get; set; }

        [Order( DisplayOrder = 5, EditOrder = 0 )]
        public Status Status { get; set; }

        [Numeric( EnableStep = true, ShowStepButtons = true, Step = 100 )]
        [Order( DisplayOrder = 4, EditOrder = 1 )]
        public decimal Balance { get; set; }

        [IgnoreField]
        public string FieldToBeIgnored { get; set; }

        [Order( DisplayOrder = 5, EditOrder = 0 )]
        [Display( Name = "Gender" )]
        [Select( GetDataFunction = "GetGenders", TextField = nameof( Blazorise.Shared.Data.Gender.Description ), ValueField = nameof( Blazorise.Shared.Data.Gender.Code ) )]
        public string Gender { get; set; }

        [Order( DisplayOrder = 6, EditOrder = 6 )]
        [Display( Name = "DOB" )]
        [Date( InputMode = DateInputMode.Date )]
        public DateOnly DateOfBirth { get; set; }

        public IEnumerable<Gender> GetGenders()
            => EmployeeData.Genders;
    }

    public enum Status
    {
        Active,
        Inactive
    }

    private IEnumerable<Example> data = new List<Example>()
    {
        new(){ FirstName = "John", LastName = "Doe", Gender = "M", Age = 30, Balance = 1000, Status = Status.Active, FieldToBeIgnored = "4a92b1ea-e82d-4920-8d22-198a2385945e", DateOfBirth = new DateOnly(1992,03,05) },
        new(){ FirstName = "Jane", LastName = "Doe", Gender = "F",Age = 28, Balance = 2000, Status = Status.Active, FieldToBeIgnored = "cb85ede4-4a66-4ab5-813d-6f09b4781489", DateOfBirth = new DateOnly(1972,03,03) },
        new(){ FirstName = "Joe", LastName = "Doe", Gender = "M",Age = 26, Balance = 3000, Status = Status.Inactive, FieldToBeIgnored = "0725a26f-1b5c-4659-be06-2b4b108a2fb4", DateOfBirth = new DateOnly(1981,12,05) },
        new(){ FirstName = "Jill", LastName = "Doe", Gender = "F",Age = 24, Balance = 4000, Status = Status.Inactive, FieldToBeIgnored = "bb85d60c-96fa-4137-a9f1-e09ec0497f5d", DateOfBirth = new DateOnly(1980,05,29) },
        new(){ FirstName = "Jack", LastName = "Doe", Gender = "M",Age = 22, Balance = 5000, Status = Status.Active, FieldToBeIgnored = "76471dfe-2efd-4ec5-b192-82abc1b05c72", DateOfBirth = new DateOnly(1990,09,10) },
        new(){ FirstName = "Jen", LastName = "Doe",Gender = "F", Age = 20, Balance = 6000, Status = Status.Active, FieldToBeIgnored = "be83a3c0-9636-4ebd-acca-08e6ffb5c469", DateOfBirth = new DateOnly(2000,01,01) },
    };

}